10 CLS:KEY OFF:SCREEN 1:DIM F1(15),I$(22)   ' 1802draw.bas
20 PRINT "1802 Draw Program by Eric F. Tchong":PRINT
30 PRINT "Data will be saved in: 1802DATA.BAS":PRINT
40 PRINT "Press to start..."
50 A$="   "+CHR$(24)+CHR$(25)+CHR$(27)+CHR$(26)
60 OPEN "O",#1,"1802DATA.BAS":D=1010
70 I$=INKEY$:IF I$="" THEN 70
80 LINE (0,0)-(2,2),15,BF:GET(0,0)-(2,2),F1
90 CLS
100 LOCATE 17,1:PRINT A$;" - move pixel"
110 LOCATE 18,1:PRINT "    Tab - line draw"
120 LOCATE 19,1:PRINT "  Space - draw or erase"
130 LOCATE 20,1:PRINT "    C/c - clear screen":PRINT
140 LOCATE 21,1:PRINT "   Home - line 1, pos 1"
150 LOCATE 22,1:PRINT "    End - end of line"
160 LOCATE 23,1:PRINT "    Esc - exit program"
170 X=0:Y=9:L=1:P=1:Q=0
180 FOR Z=1 TO 33
190   PUT(Q,1) ,F1,XOR
200   PUT(Q,79),F1,XOR
210   Q=Q+6
220 NEXT:SW=1:GOSUB 840
230 LOCATE 12,1:PRINT "line =";L;"   pos =";P;" "
240 ' Scan Keys
250 W$=INKEY$:IF W$="" THEN 250
260 IF W$=CHR$(27) THEN 430
270 IF W$=" " THEN PUT(X,Y),F1,XOR
280 IF W$="C" OR W$="c" THEN 90
290 IF W$=CHR$(9) THEN GOSUB 840
300 IF W$=CHR$(0)+CHR$(71) THEN X=0:Y=9:L=1:P=1:GOTO 230 ' home
310 IF W$=CHR$(0)+CHR$(79) THEN X=189:P=64:GOTO 230      ' end
320 IF SW=1 THEN GOSUB 730:GOTO 230
330 IF W$=CHR$(0)+CHR$(77) THEN X=X+3:P=P+1  ' right
340 IF W$=CHR$(0)+CHR$(75) THEN X=X-3:P=P-1  ' left
350 IF W$=CHR$(0)+CHR$(72) THEN Y=Y-3:L=L-1  ' up
360 IF W$=CHR$(0)+CHR$(80) THEN Y=Y+3:L=L+1  ' down
370 IF X<0 THEN X=0 ELSE IF X>189 THEN X=189 ' 63 * 3
380 IF Y<9 THEN Y=9 ELSE IF Y>72  THEN Y=72  ' 24 * 3
390 IF P<1 THEN P=1 ELSE IF P>64 THEN P=64
400 IF L<1 THEN L=1 ELSE IF L>22 THEN L=22
410 GOTO 230
420 ' Save pixels in I$(1..22)
430 Y=9:L=22
440 FOR Z=1 TO L:I$(Z)=""
450   FOR X=0 TO 189 STEP 3
460     IF POINT(X,Y)=0 THEN I$(Z)=I$(Z)+"0" ELSE I$(Z)=I$(Z)+"1"
470   NEXT:Y=Y+3
480 NEXT
490 ' Send pixels info to harddisk
500 N=0:M=7:P=0
510 GOSUB 700
520 PRINT #1,D$;" DATA ";
530 ' Convert binary to decimal
540 FOR Z=1 TO L:T=0
550   FOR Q=1 TO 64:T=T+1
560     IF MID$(I$(Z),Q,1)="1" THEN N=N+1*2^M
570     M=M-1
580     IF T=8 THEN GOSUB 630
590   NEXT Q
600 NEXT Z
610 SCREEN 2:SCREEN 0:CLOSE #1:END
620 ' Save in DATA 1,2,3,4,5,6,7,8 form
630 M=7:T=0:P=P+1
640 N$=STR$(N):N$=RIGHT$(N$,LEN(N$)-1)
650 IF P/8=INT(P/8)THEN D=D+10:PRINT #1,N$ ELSE PRINT #1,N$;",";
660 IF P/8=INT(P/8)THEN GOSUB 700:PRINT #1,D$;" DATA ";
670 N=0
680 RETURN
690 ' Remove the space in front of the number
700 D$=STR$(D):D$=RIGHT$(D$,LEN(D$)-1)
710 RETURN
720 ' Draw lines
730 IF W$=CHR$(0)+CHR$(77) THEN X=X+3:P=P+1  ' right
740 IF W$=CHR$(0)+CHR$(75) THEN X=X-3:P=P-1  ' left
750 IF W$=CHR$(0)+CHR$(72) THEN Y=Y-3:L=L-1  ' up
760 IF W$=CHR$(0)+CHR$(80) THEN Y=Y+3:L=L+1  ' down
770 IF X<0 THEN X=0 ELSE IF X>189 THEN X=189 ' 63 * 3
780 IF Y<9 THEN Y=9 ELSE IF Y>72  THEN Y=72  ' 24 * 3
790 IF P<1 THEN P=1 ELSE IF P>64 THEN P=64
800 IF L<1 THEN L=1 ELSE IF L>22 THEN L=22
810 PUT(X,Y),F1,XOR
820 RETURN
830 ' Line Draw ON or OFF
840 IF SW=0 THEN SW=1 ELSE IF SW=1 THEN SW=0
850 IF SW=1 THEN LOCATE 14,1:PRINT "line draw on ":RETURN
860 LOCATE 14,1:PRINT "line draw off":RETURN
